<?php
/**
 * <pre>
 * <b>RUBIK IT Solution & Development ltd.</b>
 *
 * PROJECT      : rubik-base
 * COPYRIGHT    : 2008
 * ------------------------------------------------------
 * 
 * [GENERAL INFO OF THIS FILE] 
 *
 * </pre>
 * 
 * @version 		1.0
 * @author			Dang Nhon Hoa <hoadn@rubik.com.vn>
 * @access			public
 * @package			rubik.base.html
 *
 * Created on	: May 25, 2008
 */
RExtImporter::cls('ajaxfileupload.AjaxHtmlUploadControl');

class AjaxImageHtmlUploadControl extends AjaxHtmlUploadControl {
	
	var $_width = null;
	var $_height = null;
	
	function setSize($width, $height) {
		$this->_width = $width;
		$this->_height = $height;
	}
	
	function getPreviewHtml() {

		$js = '
		function processSuccess(data, id) {
			id = id.replace("_id", "_img");
			$(id).attr("src", SYS_ROOT_URL + data.file);
		}
		';
		SysResponse::addJavascriptContent($js);
		
		if ($this->_width) {
			$width = "width=\"{$this->_width}px\"";
		}

		if ($this->_height) {
			$height = "height=\"{$this->_height}px\"";
		}
		
		$imgLink = RubikHelper::checkAndAddImageURL($this->_value, $this->_width, $this->_height);
		$id = $this->_inputName."_img";
		$result = '
			<img src="'.$imgLink.'" alt="" '.$width.' '.$height.' id="'.$id.'" /><br />
		';
		return $result;
	}
}
?>
